package org.gruposp2p.openid.provider;

import java.util.Collection;
import org.springframework.security.core.GrantedAuthority;
import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser;
import java.util.Date;
import org.springframework.security.core.userdetails.UserDetails;
import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser;
import org.springframework.security.core.GrantedAuthority;

class UserDNI {
	
	static hasMany = [ addresses : Address, accounts : Account, photos: Photo ]
	                   
	//automatically updated for by GORM
	Date dateCreated
	Date lastUpdated

	String username
	String password
	String email
	String userOpenID;
	String nif;
	String phone;
	String blogURL
	Date dateOfBird
	boolean enabled
	boolean accountNonExpired
	boolean accountNonLocked
	boolean credentialsNonExpired	
	
	static constraints = {
		addresses nullable:true
		accounts nullable:true
		photos nullable: true
		username blank: false, unique: true
		password blank: false
		email email:true, blank:false
		userOpenID blank: false
		nif blank: false
		phone nullable:true
		blogURL nullable: true, url: true
		dateOfBird nullable: true
	}

	static mapping = {
		password column: '`password`'
	}

	Collection<RoleDNI> getAuthorities() {
		UserDNIRoleDNI.findAllByUserDNI(this).collect { it.roleDNI } as Set
	}
	
	@Override
	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}		

	@Override
	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}		

	@Override
	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}
	
	@Override
	public boolean isEnabled() {
		return enabled;
	}
	
}

